<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet"href="/css/plat-style.css">
    <style>
        thead tr th{text-align: center!important;font-weight: bold!important;}
        tr td{text-align: center!important;}
        .layui-table img {
            width: auto;
            height: auto;
            max-width: 100% !important;
            max-height: 100%;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>模板类型</th>
                            <th>首页显示</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list}" var="l">
                            <tr>
                                <td width="10%">${l.id}</td>
                                <td width="10%">${l.name}</td>
                                <td width="10%">${l.modelName}</td>
                                <td width="10%">
                                    <c:if test="${l.display==1}"><span class="green">是</span></c:if>
                                    <c:if test="${l.display==0}"><span class="red">否</span></c:if>
                                </td>
                                <td width="20%">
                                    <button data-id="${l.id}" data-model="${l.modelType}" data-type="showThis" type="button"
                                            class="layui-btn layui-btn-sm layui-btn-normal showThis">进入版块</button>
                                    <button data-id="${l.id}" data-type="editThis" type="button"
                                            class="layui-btn layui-btn-sm layui-btn-primary editThis">编辑</button>
                                    <c:if test="${l.display==1}">
                                        <button data-id="${l.id}" data-display="0" data-type="updateThis" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-warm updateThis">隐藏</button>
                                    </c:if>
                                    <c:if test="${l.display==0}">
                                        <button data-id="${l.id}" data-display="1" data-type="updateThis" type="button"
                                                class="layui-btn layui-btn-sm updateThis">显示</button>
                                    </c:if>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$,
            form = layui.form,
            element = layui.element,
            layer = layui.layer;
        form.render('select');
        element.render();

        var active = {
            editThis: function (id) {
                layer.open({
                    title:'新增/编辑首页版块',
                    type: 2,
                    area: ['500px', '350px'],
                    content: '/app/appHomeEdit?id='+id
                });
            },
            showThis:function (id,modelType) {
                //商品推荐
                if(modelType==1){
                    window.location.href = "/app/recommend?parentId="+id;
                }
                //每日必逛
                if(modelType==2){
                    window.location.href = "/app/daily?parentId="+id;
                }
            },
            updateThis:function (id, display,url) {
                layer.confirm('确定操作吗?',function () {
                    $.ajax({
                        url: url,
                        data: {'id': id, "display": display},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.status) {
                                layer.msg(data.desc);
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg(data.desc);
                            }
                        }
                    })
                })
            }
        };
        //编辑版块信息
        $('.editThis').on('click', function(){
            var id = $(this).data('id');
            var type = 'editThis';
            active[type] && active[type].call(this,id);
        });
        //显示版块内容
        $('.showThis').on('click',function () {
            var id = $(this).data('id');
            var modelType = $(this).data('model');
            var type = $(this).data('type');
            active[type] && active[type].call(this,id,modelType);
        });
        //显示隐藏
        $('.updateThis').on('click',function () {
            var id = $(this).data('id');
            var type = $(this).data('type');
            var display = $(this).data('display');
            var url = "/app/handleAppHomeDisplay";
            active[type] && active[type].call(this,id,display,url);
        });
    });
</script>
</body>
</html>